/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller.ShowServlet;

import Ultility.RandomCollection;
import Ultility.StringCollection;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.ObjectBean.RequestBean.confirm;
import Ultility.CaptchaImage;
import java.io.File;

/**
 *
 * @author chickencake1
 */
public class ShowRegisterServlet extends HttpServlet {

    
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       
        
        
        confirm conf =new confirm();
       String captchar=RandomCollection.ChacractersRandom();
       //String captchar=StringCollection.getConfirmCharacters();
        String font=RandomCollection.FontRandom();
       conf.setConfirmcode(captchar);
       req.setAttribute("conf", conf);
       /*
        * Make an captcha with randomcharacters
        */    resp.setHeader("Cache-Control", "no-cache");
        
        //Chi dinh caches khong lu tru page duoi bat cu hoan canh nao
        resp.setHeader("Cache-Control", "no-store");        
        resp.setHeader("Pragma", "no-cache"); // HTTP 1.0. backward compatibility
        
        // Lam cho proxy caches bit day la mot old page
        resp.setDateHeader("Expires", 0); // Proxies.
       String url_relative="Resources/CaptchaImage.jpg";
       String url_absolute="C:/Users/chickencake1/Dropbox/Shared Project/Khang/GreenBookOnline/web/Resources/CaptchaImage.jpg";
       conf.setUrl(url_relative);
       File file=new File(url_absolute);
       CaptchaImage.writeJPEG(CaptchaImage.makeMessageImage(captchar,font,20),file);
       RequestDispatcher dispatcher=req.getRequestDispatcher("/WEB-INF/MainJSP/RegisterPage.jsp");
       dispatcher.forward(req, resp);
       
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

        
}
